package top.ezzz.chats.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.solon.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.noear.solon.annotation.*;
import top.ezzz.common.R;
import top.ezzz.chats.entity.Friend;
import top.ezzz.chats.service.IFriendService;
import top.ezzz.common.PageUtil;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author shenmk
 * @since 2024-01-08
 */
@Api("friend")
@Controller
@Mapping("/chats/friend")
public class FriendController {

    @Inject
    private IFriendService friendService;

    @ApiOperation("page")
    @Get
    @Mapping("page")
    public R page(Friend param) {
        Page<Friend> page = PageUtil.startPage();
        QueryWrapper<Friend> wrapper = new QueryWrapper<>(param);
        Page<Friend> friendIPage = (Page<Friend>) friendService.page(page, wrapper);
        return R.ok(friendIPage);
    }

    @ApiOperation("get")
    @Get
    @Mapping("get")
    public R get(Friend param) {
        QueryWrapper<Friend> wrapper = new QueryWrapper<>(param);
        Friend result =  friendService.getOne(wrapper);
        return R.ok(result);
    }

    @ApiOperation("insert")
    @Post
    @Mapping("insert")
    public R insert(Friend param) {
        boolean result =  friendService.save(param);
        return R.ok(result);
    }

    @ApiOperation("update")
    @Put
    @Mapping("update")
    public R update(Friend param) {
        boolean result =  friendService.updateById(param);
        return R.ok(result);
    }

    @ApiOperation("delete")
    @Delete
    @Mapping("delete")
    public R delete(Friend param) {
        boolean result =  friendService.removeById(param);
        return R.ok(result);
    }

}
